home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dd / dism.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  5KB  |  205 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. #include    "defs.h"
  7. #include    "dbug_protos.h"
  8.  
  9. // ************************************************************************
  10.  
  11. Prototype BOOL        DownDism(void);
  12. Prototype BOOL        UpDism(void);
  13. Prototype BOOL        PageDownDism(void);
  14. Prototype BOOL        PageUpDism(void);
  15. Prototype WORD        RefreshDism(short maxLines, BOOL fullRefresh);
  16. Prototype ULONG     PreviousInstruction(ULONG addr);
  17.  
  18. // ************************************************************************
  19.  
  20. BOOL    DownDism(void) {
  21.     ULONG    val;
  22.  
  23.     val = Disassemble(CurDisplay->ds_WindowTop, CurDisplay->ds_WindowTop, LineBuf);
  24.     CurDisplay->ds_WindowTop += val;
  25.  
  26.     if (CurDisplay->ds_DisplayMode != CurDisplay->ds_LastRefreshMode) {
  27.         RefreshWindow(1);
  28.         return TRUE;
  29.     }
  30.     CurDisplay->ds_LastRefreshTop = CurDisplay->ds_WindowTop;
  31.     ScrScrollup();
  32.  
  33.     CurDisplay->ds_WindowBot += Disassemble(CurDisplay->ds_WindowBot, CurDisplay->ds_WindowBot, LineBuf);
  34.     Disassemble(CurDisplay->ds_WindowBot, CurDisplay->ds_WindowBot, LineBuf);   // actual next inst
  35.  
  36.     if (CurDisplay->ds_WindowBot == programPC) ScrHighlight();
  37.     if (IsBreakpoint(CurDisplay->ds_WindowBot)) ScrUnderline();
  38.     PrintAddress(CurDisplay->ds_WindowBot);
  39.     if (!CurDisplay->ds_DisplayOffsets) {
  40.         char    *s;
  41.  
  42.         s = LookupValue(CurDisplay->ds_WindowBot);
  43.         if (!s) s = "";
  44.         ScrPrintf("%-16.16s %s", s, LineBuf);
  45.     }
  46.     else ScrPuts(LineBuf);
  47.     ScrEOL();
  48.     ScrPlain();
  49.     RefreshWindow(FALSE);
  50.     return TRUE;
  51. }
  52.  
  53. BOOL    UpDism(void) {
  54.  
  55.     if (CurDisplay->ds_DisplayMode != CurDisplay->ds_LastRefreshMode) {
  56.         RefreshWindow(TRUE);
  57.         return TRUE;
  58.     }
  59.  
  60.     CurDisplay->ds_LastRefreshTop = CurDisplay->ds_WindowTop = PreviousInstruction(CurDisplay->ds_WindowTop);
  61.  
  62.     ScrScrolldown();
  63.  
  64.     if (CurDisplay->ds_WindowTop == programPC) ScrHighlight();
  65.     if (IsBreakpoint(CurDisplay->ds_WindowTop)) ScrUnderline();
  66.     PrintAddress(CurDisplay->ds_WindowTop);
  67.     if (!CurDisplay->ds_DisplayOffsets) {
  68.         char    *s;
  69.  
  70.         s = LookupValue(CurDisplay->ds_WindowTop);
  71.         if (!s) s = "";
  72.         ScrPrintf("%-16.16s %s", s, LineBuf);
  73.     }
  74.     else ScrPuts(LineBuf);
  75.     ScrEOL();
  76.     ScrPlain();
  77.     RefreshWindow(FALSE);
  78.     return TRUE;
  79. }
  80.  
  81.  
  82. BOOL    PageUpDism(void) {
  83.     ULONG address = CurDisplay->ds_WindowTop;
  84.     int i,     lines = CalcDisplayLines();
  85.  
  86.     if (CurDisplay->ds_DisplayMode != CurDisplay->ds_LastRefreshMode) {
  87.         RefreshWindow(TRUE);
  88.         return TRUE;
  89.     }
  90.  
  91.     if(lines > 0) {
  92.         for(i=0; i<lines; i++)address = PreviousInstruction(address);
  93.         CurDisplay->ds_WindowTop = address;
  94.         CurDisplay->ds_WindowTopLine = 0;
  95.         RefreshWindow(1);
  96.     }
  97.     return TRUE;
  98. }
  99.  
  100. BOOL    PageDownDism(void) {
  101.     if (CurDisplay->ds_DisplayMode != CurDisplay->ds_LastRefreshMode) {
  102.         RefreshWindow(TRUE);
  103.         return TRUE;
  104.     }
  105.     CurDisplay->ds_WindowTop = CurDisplay->ds_WindowBot;
  106.     CurDisplay->ds_WindowTopLine = 0;
  107.     RefreshWindow(1);
  108.     return TRUE;
  109. }
  110.  
  111. WORD    RefreshDism(short maxLines, BOOL fullRefresh) {
  112.     ULONG    address = CurDisplay->ds_WindowTop, size;
  113.     WORD    count = 0;
  114.     char    *s;
  115.     BOOL    plotFlag;
  116.  
  117.     
  118.  
  119.     do_scroller();
  120. //    if (fullRefresh) {
  121.         if (fullRefresh)SetTitle(NULL,NULL);
  122. #if 0
  123.         ScrPlain();
  124.         ScrInverse();
  125.         ScrPuts("DISM MODE");
  126. #endif
  127.         // add a seperation between register display and source
  128.  
  129.         if(CurDisplay->ds_RegFlag) {
  130.             ++count;
  131.             Newline();
  132.             if (--maxLines == 0)return count;
  133.         }
  134. //    }
  135.  
  136.  
  137.     while (maxLines > 0) {
  138.         plotFlag = fullRefresh;
  139.         CurDisplay->ds_WindowBot = address;
  140.         size = Disassemble(address, address, LineBuf);
  141.         ScrPlain();
  142.  
  143.         plotFlag = TRUE; 
  144.  
  145.         if (address == programPC) { 
  146.             plotFlag = TRUE; 
  147.             ScrHighlight(); 
  148.         }
  149.         if (IsBreakpoint(address)) { 
  150.             plotFlag = TRUE; 
  151.             ScrUnderline(); 
  152.         }
  153.         if (address == lastPC) { 
  154.             plotFlag = TRUE; 
  155.             ScrPlain(); 
  156.         }
  157.         if (plotFlag) {
  158.             PrintAddress(address);
  159.             if (!CurDisplay->ds_DisplayOffsets) {
  160.                 s = LookupValue(address);
  161.                 if (!s) s = "";
  162.                 ScrPrintf("%-16.16s %s", s, LineBuf);
  163.             }
  164.             else ScrPuts(LineBuf);
  165.             count++;
  166.             ScrPutNewline(); 
  167.             maxLines--;
  168.         }
  169.         else {
  170.             count++;
  171.             ScrPutNewline();
  172.             maxLines--;
  173.         }
  174.         address += size;
  175.     }
  176.     return count;
  177. }
  178.  
  179. /*  Attempt to find previous instruction. This is done by
  180.  *  searching forward from the nearest label address or
  181.  *  20 words back, whichever is closer.
  182.  */
  183.  
  184. ULONG    PreviousInstruction(ULONG addr) {
  185.     ULONG val;
  186.     ULONG siz;
  187.     char *s;
  188.  
  189.     if (s = NearestValue(addr-2)) {
  190.         LookupSymbol(s, &val);
  191.         if ((long)(addr - val) > 40 || (long)(addr - val) <= 0)
  192.             val = addr - 40;
  193.     }
  194.     else val = addr - 40;
  195.  
  196.     siz = 0;
  197.     while (val + siz < addr) {
  198.         val = val + siz;
  199.         siz = Disassemble(val, val, LineBuf);
  200.         if ((long)siz <= 0)siz = 2;     //  if siz is weird
  201.     }
  202.     return(val);
  203. }
  204.  
  205.